package cn.piggy.gateway.core.datasource.unpooled;

import cn.piggy.gateway.core.datasource.DataSource;
import cn.piggy.gateway.core.datasource.DataSourceFactory;
import cn.piggy.gateway.core.config.ConfigHelper;


public class UnpooledDataSourceFactory implements DataSourceFactory {

    protected UnpooledDataSource dataSource;

    public UnpooledDataSourceFactory(ConfigHelper configuration, String uri) {
        this.dataSource = new UnpooledDataSource();
        this.dataSource.setConfiguration(configuration);
        this.dataSource.setHttpStatement(configuration.getHttpStatement(uri));
    }

    public UnpooledDataSourceFactory() {
        this.dataSource = new UnpooledDataSource();
    }

    @Override
    public void setProperties(ConfigHelper configuration, String uri) {
        this.dataSource.setConfiguration(configuration);
        this.dataSource.setHttpStatement(configuration.getHttpStatement(uri));
    }

    @Override
    public DataSource getDataSource() {
        return dataSource;
    }

}
